package com.ruoyi.system.service.impl.fxImpl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.fx.FxUser;
import com.ruoyi.system.domain.fx.FxWithdrawalAccount;
import com.ruoyi.system.mapper.fx.FxStoreMapper;
import com.ruoyi.system.mapper.fx.FxUserMapper;
import com.ruoyi.system.mapper.fx.FxWithdrawalAccountMapper;
import com.ruoyi.system.service.fx.IFxWithdrawalAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * 提现账号管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-09-12
 */
@Service
public class FxWithdrawalAccountServiceImpl implements IFxWithdrawalAccountService
{
    @Autowired
    private FxWithdrawalAccountMapper fxWithdrawalAccountMapper;

    @Autowired
    private FxUserMapper fxUserMapper;

    /**
     * 查询提现账号管理
     * 
     * @param id 提现账号管理主键
     * @return 提现账号管理
     */
    @Override
    public FxWithdrawalAccount selectFxWithdrawalAccountById(Long id)
    {
        return fxWithdrawalAccountMapper.selectFxWithdrawalAccountById(id);
    }

    /**
     * 查询提现账号管理列表
     * 
     * @param fxWithdrawalAccount 提现账号管理
     * @return 提现账号管理
     */
    @Override
    public List<FxWithdrawalAccount> selectFxWithdrawalAccountList(FxWithdrawalAccount fxWithdrawalAccount)
    {
        return fxWithdrawalAccountMapper.selectFxWithdrawalAccountList(fxWithdrawalAccount);
    }

    /**
     * 体现账号下拉
     * @return
     */
    @Override
    public List<FxWithdrawalAccount> optionList() {
        FxWithdrawalAccount fxWithdrawalAccount = new FxWithdrawalAccount();
        FxUser fxUser = fxUserMapper.selectFxUserByUserId(SecurityUtils.getUserId());
        if (StringUtils.isNotNull(fxUser) && StringUtils.isNotNull(fxUser.getStoreId())) {
            fxWithdrawalAccount.setMerchantId(fxUser.getStoreId());
            return fxWithdrawalAccountMapper.selectFxWithdrawalAccountList(fxWithdrawalAccount);
        }
        return null;
    }

    /**
     * 新增提现账号管理
     * 
     * @param fxWithdrawalAccount 提现账号管理
     * @return 结果
     */
    @Override
    public int insertFxWithdrawalAccount(FxWithdrawalAccount fxWithdrawalAccount)
    {
        fxWithdrawalAccount.setCreateTime(DateUtils.getNowDate());
        return fxWithdrawalAccountMapper.insertFxWithdrawalAccount(fxWithdrawalAccount);
    }

    /**
     * 新增或编辑
     * @param list
     * @return
     */
    @Override
    @Transactional
    public void insertAccountLIst(List<FxWithdrawalAccount> list) {
        if (StringUtils.isNotEmpty(list)) {
            Long storeId = list.get(0).getMerchantId();
            fxWithdrawalAccountMapper.deleteByMerchantId(storeId);
            list.forEach(item -> {
                item.setCreateTime(DateUtils.getNowDate());
                fxWithdrawalAccountMapper.insertFxWithdrawalAccount(item);
            });
        }
    }

    /**
     * 修改提现账号管理
     * 
     * @param fxWithdrawalAccount 提现账号管理
     * @return 结果
     */
    @Override
    public int updateFxWithdrawalAccount(FxWithdrawalAccount fxWithdrawalAccount)
    {
        fxWithdrawalAccount.setUpdateTime(DateUtils.getNowDate());
        return fxWithdrawalAccountMapper.updateFxWithdrawalAccount(fxWithdrawalAccount);
    }

    /**
     * 批量删除提现账号管理
     * 
     * @param ids 需要删除的提现账号管理主键
     * @return 结果
     */
    @Override
    public int deleteFxWithdrawalAccountByIds(Long[] ids)
    {
        return fxWithdrawalAccountMapper.deleteFxWithdrawalAccountByIds(ids);
    }

    /**
     * 删除提现账号管理信息
     * 
     * @param id 提现账号管理主键
     * @return 结果
     */
    @Override
    public int deleteFxWithdrawalAccountById(Long id)
    {
        return fxWithdrawalAccountMapper.deleteFxWithdrawalAccountById(id);
    }
}
